package com.hgd.security.evp.biz.rest;

import com.hgd.security.evp.biz.biz.EvpHarmfulComponentsBiz;
import com.hgd.security.evp.biz.entity.EvpHarmfulComponents;
import com.hgd.security.evp.common.util.ObjectResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("evpHarmfulComponents")
@Api(tags = "有害气体管理")
public class EvpHarmfulComponentsController {

    @Autowired
    private EvpHarmfulComponentsBiz evpHarmfulComponentsBiz;

    @PostMapping("/instance")
    @ApiOperation("添加单个对象")
    public ObjectResultResponse<Void> addEvpHarmFC(
        @RequestBody @ApiParam(value = "待添加对象实例") EvpHarmfulComponents evpHarmfulComponents,
        BindingResult bindingResult) {
        ObjectResultResponse<Void> restresult = new ObjectResultResponse<>();

        if (bindingResult.hasErrors()) {
            restresult.setMessage(bindingResult.getAllErrors().get(0).getDefaultMessage());
            restresult.setStatus(400);
            return restresult;
        }

        return evpHarmfulComponentsBiz.addEvpHarmFC(evpHarmfulComponents);
    }
}